<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>订单查询</title>
    <link rel="stylesheet" href="__STATIC__/cash/css/order.css">
    <script src="__STATIC__/cash/js/jquery-3.2.1.min.js"></script>
    <link rel="stylesheet" href="__STATIC__/plugs/layui/css/layui.css?ver={:date('ymd')}" />
    <script src="__STATIC__/plugs/layui/layui.all.js" charset="utf-8"></script>
</head>

<body>
    <header>
        <div>
            <img src="__STATIC__/cash/img/logo.png" alt="">
            <div>订单查询</div>
        </div>
        <div>
            <a href="{:url('Index/index')}">
                返回
            </a>
        </div>
    </header>
    <form>
        <div class="headline">
            <div>
                <div>订单</div>
                <input type="text" name="key" value="{$key}" placeholder="请输入订单号">
                <a href="javascript:;" onclick="search_init()">查询</a>
                 <a href="javascript:;" onclick="search_one()">退款订单查询</a>
                <a href="javascript:;" onclick="search_two()">预订/自取</a>
            </div>
            <div>
                <div>编号</div>
                <div>订单金额</div>
                <div>时间</div>
                <div>操作</div>
            </div>
        </div>
    </form>
    <div class="content">
        {if condition="!empty($order)"}
            {foreach name="order" item="v"}
                <div class="list" onclick="get_order_details({$v.id})">
                    <div>
                        <div>{$v.order_sn}</div>
                        <div>{$v.final_amount}</div>
                        <div>{$v.addtime|date="Y-m-d H:i",###}</div>
                    </div>
                    {if condition="$order_type eq 2"}
                        {if condition="$v.is_yuding"}
                            {if condition="$v.ziqu_time eq 0"}
                                <div onclick="pupopclick(1)">取货</div>
                            {else /}
                            <div >完成</div>
                            {/if}
                        {/if}
                    {elseif condition="$order_type eq 1" /}
                        {if condition="$v.is_tuikuan eq 1"}
                            <div onclick="pupopclick(3)">已退款</div>
                        {else /}
                            <div onclick="pupopclick(3)">退款</div>
                        {/if}
                    {else /}
                        <div onclick="pupopclick(2)">打印</div>
                    {/if}
                </div>
            {/foreach}
        {/if}
    </div>

    <div class="pupop"></div>
    <div class="pupop-content">
        <div class="pupop-headline">
            订单详情
        </div>
        <div>
            <div>商品</div>
            <div>规格</div>
            <div>单价</div>
            <div>数量</div>
            <div>折扣</div>
        </div>
        <div id="pupop-roll">
            <!-- 循环开始 -->
            <!-- 循环结束 -->
        </div>
        <div>
            <div>
                <div id="pay_time">付款时间：2018.05.21 11:22:41</div>
                <div id="goods_price">总计：55.00</div>
            </div>
            <div id="coupon_price">优惠：12.00</div>
        </div>
        <div>
            <div>
                <div>收款</div>
                <div id="pay_one">微信20.00</div>
                <div id="pay_two">支付宝20.00</div>
            </div>
            <div id="pay_amount">收款：40.00</div>
        </div>
        <a href="javascript:;" onclick="dayin()" id="dayin">打印</a>
        <a href="javascript:;" onclick="quhuo()" id="quhuo" style="display:none;">取货</a>
        <a href="javascript:;" onclick="tuikuan()" id="tuikuan" style="display:none;">退款</a>
        <div onclick="guanbi()">关闭</div>
        <div id="final_amount">0</div>
        <div id="order_id">0</div>
    </div>
    <!--打印区域 start-->
        <div style="display: none">
            <div id="print-area">
                <table id="print">
                </table>
            </div>
        </div>
    <!--打印区域 end-->
    <script>
        /**
         * 操作方法
         * @param type  1取货，2打印
         */
        function pupopclick(type) {
            if(type == 1){          //取货
                $('#dayin').css('display','none');
                $('#quhuo').css('display','block');
                $('#tuikuan').css('display','none');
            }else if(type == 2){
                $('#dayin').css('display','block');
                $('#quhuo').css('display','none');
                $('#tuikuan').css('display','none');
            }else{
                $('#dayin').css('display','none');
                $('#quhuo').css('display','none');
                $('#tuikuan').css('display','block');
            }
            $('.pupop').css('display', 'block');
            $('.pupop-content').css('display', 'block');
        };
        $(function () {
            // 订单信息弹出层

            $('.pupop-click').click(function () {});
            $('.pupop-esc').click(function () {
                $('.pupop').css('display', 'none');
                $('.pupop-content').css('display', 'none');

            });
            $('.pupop').click(function () {
                $('.pupop').css('display', 'none');
                $('.pupop-content').css('display', 'none');
            });
        });
    </script>
    <script>
        /**
         * 普通查询
         */
        function search_init(){
            var key = $('input[name=key]').val();
            window.location.href = "{:url('Order/index')}?order_type=0&key="+key;
        }

        /**
         * 退款查询
         */
        function search_one(){
            var key = $('input[name=key]').val();
            window.location.href = "{:url('Order/get_tuikuan_order')}?order_type=1&key="+key;
        }

        /**
         * 自取查询
         */
        function search_two(){
            var key = $('input[name=key]').val();
            window.location.href = "{:url('Order/index')}?order_type=2&key="+key;
        }
        /**
         * 查询订单详情
         * @param order_id
         */
        function get_order_details(id){
            $.post("{:url('Order/get_order_details')}",
                {order_id:id},
                function(data){
                    if(data.code == 1){
                        var html = '';
                        for(var i=0;i<data.data['list'].length;i++){
//                            console.log(data.data[i].spec_detail);
                            if(data.data['list'][i]['spec_detail'] == null){
//                                console.log(data.data[i]["spec_detail"]);
                                var title = '无';
                            }else{
                                var title = data.data['list'][i]['spec_detail'];
                            }
                            if(data.data['list'][i]['discount_num'] == null){
                                var discount = '无';
                            }else{
                                var discount = data.data['list'][i]['discount_num'];
                            }

                            html += '<div><div><p>'+data.data['list'][i]["name"]+'</p></div><div>'+title+'</div><div>'+data.data['list'][i]["spec_price"]+'</div><div>'+data.data['list'][i]["goods_num"]+'</div><div>'+discount+'</div></div>';
                        }

                        $('#pay_time').text('付款时间：'+data.data['pay_time']);
                        $('#goods_price').text('总计：'+data.data['goods_price']);
                        $('#coupon_price').text('优惠：'+data.data['coupon_price']);

                        if(data.data['pay_type_two'] == null){
                            $('#pay_two').css('display','none');

                            if(data.data['pay_type'] == 1){
                                var title = '支付宝';
                            }else if(data.data['pay_type'] == 2){
                                var title = '微信';
                            }else if(data.data['pay_type'] == 3){
                                var title = '余额';
                            }else if(data.data['pay_type'] == 4){
                                var title = '现金';
                            }else if(data.data['pay_type'] == 5){
                                var title = '银行卡';
                            }else if(data.data['pay_type'] == 6){
                                var title = '美团';
                            }else if(data.data['pay_type'] == 7){
                                var title = '饿了么';
                            }

                            $('#pay_one').text(title+data.data['final_amount']);
                        }else{
                            $('#pay_one').text('余额：'+data.data['pay_type_two']);

                            if(data.data['pay_type'] == 1){
                                var title = '支付宝';
                            }else if(data.data['pay_type'] == 2){
                                var title = '微信';
                            }else if(data.data['pay_type'] == 3){
                                var title = '余额';
                            }else if(data.data['pay_type'] == 4){
                                var title = '现金';
                            }else if(data.data['pay_type'] == 5){
                                var title = '银行卡';
                            }else if(data.data['pay_type'] == 6){
                                var title = '美团';
                            }else if(data.data['pay_type'] == 7){
                                var title = '饿了么';
                            }

                            var amount = parseFloat(data.data['final_amount']-parseFloat(data.data['pay_type_two'])).toFixed(2);

                            $('#pay_two').text(title+amount);
                        }

                        if(data.data['is_tuikuan'] == 1){
                            $('#tuikuan').css('display','none');
                        }

                        if(data.data['ziqu_time'] == 1){
                            $('#quhuo').css('display','none');
                        }


                        $('#pay_amount').text('收款：'+data.data['final_amount']);

                        $('#pupop-roll').empty();
                        $('#pupop-roll').html(html);



                        $('#final_amount').text(data.data['final_amount']);
                        $('#order_id').text(data.data['order_id']);
                        $('.pupop').css('display','block');
                        $('.pupop-content').css('display', 'block');
                    }else{
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 1000
                        });
                        return false; //重要
                    }
                }
            );
        }
        /**
         * 关闭弹出层
         */
        function guanbi(){
            $('.pupop').css('display', 'none');
            $('.pupop-content').css('display', 'none');
        }

        /**
         * 打印
         */
        function dayin(){
            var order_id = $('#order_id').text();
            $.post("{:url('Order/get_print_data')}",
                {order_id:order_id},
                function(data){
                    if(data.code == 1){
                        $('#print').html(data.data);
                        print();
                        location.reload();
                    }else{
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 1500
                        });
                        return false; //重要
                    }
                }
            )
        }

        /**
         * 打印小票
         */
        function print(){
            if (!!window.ActiveXObject || "ActiveXObject" in window) {
                remove_ie_header_and_footer();
            }
            var newWindow = window.open("打印窗口", "_blank");
            var docStr = $("#print-area").html();
            newWindow.document.write(docStr);
            newWindow.document.close();
            newWindow.print();
            newWindow.close();
        }
        /**
         * 取出打印的页眉页脚
         */
        function remove_ie_header_and_footer(){
            var hkey_root, hkey_path, hkey_key;
            hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
            try {
                var RegWsh = new ActiveXObject("WScript.Shell");
                RegWsh.RegWrite(hkey_path + "header", "");
                RegWsh.RegWrite(hkey_path + "footer", "");
            } catch (e) {}
        }

        /**
         * 取货
         */
        function quhuo(){
            var order_id = $('#order_id').text();
            $.post("{:url('Order/quhuo')}",
                {order_id:order_id},
                function(data){
                    if(data.code == 1){
                        layer.msg('取货成功', {
                            icon: 1,
                            time: 1500
                        },function(data){
                            location.reload();
                        });
                        return false; //重要
                    }else{
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 1500
                        });
                        return false; //重要
                    }
                }
            );
        }

        /**
         * 订单退款
         */
        function tuikuan(){
            var order_id = $('#order_id').text();
            $.post("{:url('Refund/index')}",
                {order_id:order_id},
                function(data){
                    if(data.code == 1){
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000
                        },function(data){
                            location.reload();
                        });
                        return false; //重要
                    }else{
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 1500
                        });
                        return false; //重要
                    }
                }
            );
        }
    </script>
</body>

</html>